package homework11;

public class Printer {
	private int index=1;
	public synchronized void print(int i){
		try{
			Thread.sleep(100);
		}catch(InterruptedException e){
			e.printStackTrace();
		}
		while(index%3==0){
			try{
				wait();
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
		System.out.print(i);
		index++;
		this.notifyAll();
	}
	public synchronized void print(char c){
		try{
			Thread.sleep(100);
		}catch(InterruptedException e){
			e.printStackTrace();
		}
		while(index%3!=0){
			try{
				wait();
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
		System.out.print(c);
		index++;
		this.notifyAll();
	}
	public Printer(int index){
		super();
		this.index=index;
	}
	public Printer(){
		super();
	}
}
